/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * jhjhjh
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import type.AddressType;

/**
 *
 * @author Andy
 */
@Entity(name="Contact")
public class ContactEntity extends DataObjectEntity implements Serializable {

    private String email;
    @OneToMany(mappedBy="contact", cascade= CascadeType.ALL)
    private Collection<AddressEntity> addresses = new ArrayList<AddressEntity>();
    private String contactNumber;
    
    @OneToOne
    private PersonEntity person;

    public ContactEntity() {
        super();
    }

    public ContactEntity(String email, Collection<AddressEntity> addresses, String contactNumber, PersonEntity person) {
        this.email = email;
        this.addresses = addresses;
        this.contactNumber = contactNumber;
        this.person = person;
    }

    public Collection<AddressEntity> getAddresses() {
        
        return addresses;
    }

    public void setAddresses(Collection<AddressEntity> addresses) {
        this.addresses = addresses;
    }  

    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public PersonEntity getPerson() {
        return person;
    }

    public void setPerson(PersonEntity person) {
        this.person = person;
    }
    
    public ArrayList<AddressEntity> getShippingAddresses(){
        ArrayList<AddressEntity> shippings = new ArrayList<AddressEntity>();
        for(AddressEntity add : getAddresses()){
            if(add.getType()==AddressType.ShippingAddress)
                shippings.add(add);
        }
        return shippings;
    }

    @Override
    public String childToString() {
        return "ContactEntity{" + "email=" + email + ", addresses=" + addresses + ", contactNumber=" + contactNumber + ", person=" + person + '}';
    }
    
}
